﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Sector7.Restaurant.APs.ForeStation.Events;
using Sector7.Restaurant.APs.ForeStation.Entity;
using Sector7.Restaurant.APs.ForeStation.Enums;

namespace Sector7.Restaurant.APs.ForeStation.Controls
{
    /// <summary>
    /// FunctionalStrip.xaml 的交互逻辑
    /// </summary>
    public partial class FunctionalStrip : UserControl
    {
        public event FunctionClickEventHandler FunctionClick = null;

        public FunctionalStrip()
        {
            InitializeComponent();
        }

        private void LoadFunctions()
        {
            stpMain.Children.Clear();

            //------------------------------------------------------------------- 模拟数据
            List<FunctionInfor> functions = new List<FunctionInfor>();

            FunctionInfor main = new FunctionInfor("主界面");
            main.Items.Add(new FunctionItemInfor("收银台", MenuItemType.Cashiers));
            main.Items.Add(new FunctionItemInfor("预定", MenuItemType.None));
            main.Items.Add(new FunctionItemInfor("库存管理", MenuItemType.StockSummary));

            FunctionInfor restaurantManagement = new FunctionInfor("餐厅管理");
            restaurantManagement.Items.Add(new FunctionItemInfor("餐厅信息", MenuItemType.CompanyInformation));
            restaurantManagement.Items.Add(new FunctionItemInfor("员工管理", MenuItemType.EmployeeSummary));
            restaurantManagement.Items.Add(new FunctionItemInfor("菜单管理", MenuItemType.MenuSummary));
            restaurantManagement.Items.Add(new FunctionItemInfor("桌位管理", MenuItemType.TableSummary));
            restaurantManagement.Items.Add(new FunctionItemInfor("设备管理", MenuItemType.EquipmentSummary));

            FunctionInfor statisticsManagement = new FunctionInfor("数据统计");
            statisticsManagement.Items.Add(new FunctionItemInfor("费用统计", MenuItemType.ChargeSummary));

            FunctionInfor systemManagement = new FunctionInfor("系统管理");
            systemManagement.Items.Add(new FunctionItemInfor("元数据管理", MenuItemType.MetaDataSummary));
            systemManagement.Items.Add(new FunctionItemInfor("修改密码", MenuItemType.None));

            functions.Add(main);
            functions.Add(restaurantManagement);
            functions.Add(statisticsManagement);
            functions.Add(systemManagement);
            //-------------------------------------------------------------------

            foreach (var function in functions)
            {
                Button btn = new Button();
                btn.Content = function.Caption;
                btn.Tag = function.Items;
                btn.Height = 50;
                btn.Click += new RoutedEventHandler(Button_Click);

                stpMain.Children.Add(btn);
            }

            OnFunctionClick(new FunctionClickEventArgs((stpMain.Children[0] as Button).Tag as List<FunctionItemInfor>));
        }

        private void UserControl_Loaded(object sender, RoutedEventArgs e)
        {
            LoadFunctions();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            OnFunctionClick(new FunctionClickEventArgs((sender as Button).Tag as List<FunctionItemInfor>));
        }

        protected void OnFunctionClick(FunctionClickEventArgs e)
        {
            if (null != FunctionClick)
                FunctionClick(this, e);
        }
    }
}
